package invalidosgibusinesscomponentdependency;

import java.util.Arrays;
import org.eclipse.viatra2.emf.incquery.runtime.api.IPatternMatch;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BasePatternMatch;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.Pattern;
import sysmodel.BusinessComponent;
import sysmodel.OSGiBusinessComponent;

/**
 * Pattern-specific match representation of the InvalidOSGiBusinessComponentDependency pattern, 
 * to be used in conjunction with InvalidOSGiBusinessComponentDependencyMatcher.
 * 
 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
 * Each instance is a (possibly partial) substitution of pattern parameters, 
 * usable to represent a match of the pattern in the result of a query, 
 * or to specify the bound (fixed) input parameters when issuing a query.
 * 
 * @see InvalidOSGiBusinessComponentDependencyMatcher
 * @see InvalidOSGiBusinessComponentDependencyProcessor
 * 
 */
public final class InvalidOSGiBusinessComponentDependencyMatch extends BasePatternMatch implements IPatternMatch {
  private OSGiBusinessComponent fOsgiComponent;
  
  private BusinessComponent fOtherComponent;
  
  private static String[] parameterNames = {"osgiComponent", "otherComponent"};
  
  public InvalidOSGiBusinessComponentDependencyMatch(final OSGiBusinessComponent pOsgiComponent, final BusinessComponent pOtherComponent) {
    this.fOsgiComponent = pOsgiComponent;
    this.fOtherComponent = pOtherComponent;
    
  }
  
  @Override
  public Object get(final String parameterName) {
    if ("osgiComponent".equals(parameterName)) return this.fOsgiComponent;
    if ("otherComponent".equals(parameterName)) return this.fOtherComponent;
    return null;
    
  }
  
  public OSGiBusinessComponent getOsgiComponent() {
    return this.fOsgiComponent;
    
  }
  
  public BusinessComponent getOtherComponent() {
    return this.fOtherComponent;
    
  }
  
  @Override
  public boolean set(final String parameterName, final Object newValue) {
    if ("osgiComponent".equals(parameterName) && newValue instanceof sysmodel.OSGiBusinessComponent) {
    	this.fOsgiComponent = (sysmodel.OSGiBusinessComponent) newValue;
    	return true;
    }
    if ("otherComponent".equals(parameterName) && newValue instanceof sysmodel.BusinessComponent) {
    	this.fOtherComponent = (sysmodel.BusinessComponent) newValue;
    	return true;
    }
    return false;
    
  }
  
  public void setOsgiComponent(final OSGiBusinessComponent pOsgiComponent) {
    this.fOsgiComponent = pOsgiComponent;
    
  }
  
  public void setOtherComponent(final BusinessComponent pOtherComponent) {
    this.fOtherComponent = pOtherComponent;
    
  }
  
  @Override
  public String patternName() {
    return "InvalidOSGiBusinessComponentDependency";
    
  }
  
  @Override
  public String[] parameterNames() {
    return InvalidOSGiBusinessComponentDependencyMatch.parameterNames;
    
  }
  
  @Override
  public Object[] toArray() {
    return new Object[]{fOsgiComponent, fOtherComponent};
    
  }
  
  @Override
  public String prettyPrint() {
    StringBuilder result = new StringBuilder();
    result.append("\"osgiComponent\"=" + prettyPrintValue(fOsgiComponent) + ", ");
    
    result.append("\"otherComponent\"=" + prettyPrintValue(fOtherComponent)
    );return result.toString();
    
  }
  
  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((fOsgiComponent == null) ? 0 : fOsgiComponent.hashCode()); 
    result = prime * result + ((fOtherComponent == null) ? 0 : fOtherComponent.hashCode()); 
    return result; 
    
  }
  
  @Override
  public boolean equals(final Object obj) {
    if (this == obj)
    	return true;
    if (obj == null)
    	return false;
    if (!(obj instanceof IPatternMatch))
    	return false;
    IPatternMatch otherSig  = (IPatternMatch) obj;
    if (!pattern().equals(otherSig.pattern()))
    	return false;
    if (!InvalidOSGiBusinessComponentDependencyMatch.class.equals(obj.getClass()))
    	return Arrays.deepEquals(toArray(), otherSig.toArray());
    				InvalidOSGiBusinessComponentDependencyMatch other = (InvalidOSGiBusinessComponentDependencyMatch) obj;
    				if (fOsgiComponent == null) {if (other.fOsgiComponent != null) return false;}
    				else if (!fOsgiComponent.equals(other.fOsgiComponent)) return false;
    				if (fOtherComponent == null) {if (other.fOtherComponent != null) return false;}
    				else if (!fOtherComponent.equals(other.fOtherComponent)) return false;
    				return true;
    
  }
  
  @Override
  public Pattern pattern() {
    return InvalidOSGiBusinessComponentDependencyMatcher.FACTORY.getPattern();
  }
}
